package com.yexiong.server.process;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import com.common.entity.DataPack;
import com.common.entity.Event;
import com.common.entity.Parm;
import com.common.entity.Payment;
import com.common.server.view.ServerMainFrame;
import com.common.server.view.ServerProcessThread;
import com.common.server.view.ServiceProcess;
import com.yexiong.server.dao.IEventServer;
import com.yexiong.server.dao.impl.EventServerImpl;

import utils.Page;

public class EventServiceProcess implements ServiceProcess{
	private IEventServer IEventServer=new EventServerImpl();

	@Override
	public Object service(DataPack dataPack, ServerProcessThread serverProcessThread, ServerMainFrame serverMainFrame)
			throws IOException {
		if (dataPack.getOptType().equals("show")) {
			Parm parm=(Parm)dataPack.getCon();
			
			String condition=(String)parm.list.get(0);
			int currentPage=(int)parm.list.get(1);
			int pageSize=(int)parm.list.get(2);
			String startTime=(String)parm.list.get(3);
			String endTime=(String)parm.list.get(4);
			Page<Event> page=IEventServer.getPage(condition, currentPage, pageSize,startTime,endTime);
			
			serverProcessThread.getOos().writeObject(page);
			serverProcessThread.getOos().flush();
		}
		else if (dataPack.getOptType().equals("delete")) {
			String time=(String)dataPack.getCon();
			int result=0;
			result=IEventServer.delete(time);
			serverProcessThread.getOos().writeObject(result);
			serverProcessThread.getOos().flush();
		}else if (dataPack.getOptType().equals("getId")) {
			Event event=(Event)dataPack.getCon();
			int id=IEventServer.getIdByDate(new SimpleDateFormat("yyyy-MM-dd HH-mm-ss").format(event.getEventTime()));
			serverProcessThread.getOos().writeObject(id);
			serverProcessThread.getOos().flush();
		}else if (dataPack.getOptType().equals("update")) {
			Event event=(Event)dataPack.getCon();
			int result=IEventServer.update(event);
			serverProcessThread.getOos().writeObject(result);
			serverProcessThread.getOos().flush();
		}else if (dataPack.getOptType().equals("add")) {
			Event event=(Event)dataPack.getCon();
			int result=0;
			result=IEventServer.insert(event);
			serverProcessThread.getOos().writeObject(result);
			serverProcessThread.getOos().flush();
		}else if (dataPack.getOptType().equals("check")) {
			Event event=(Event)dataPack.getCon();
			int id=IEventServer.check(event);
			serverProcessThread.getOos().writeObject(id);
			serverProcessThread.getOos().flush();
		}
		return null;
	}

}
